/**
 * 
 * @authors Your Name (you@example.org)
 * @date    2018-06-04 22:52:52
 * @version $Id$
 */
// 运动兼容
window.requesAnimationFrame = window.requestAnimationFrame || function(callback){
	return setTimeout(callback, 1000/60); 
}
window.cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;

// 运动函数
function animation(obj,atter,target,speed,callback){
	var start = parseFloat(getStyle(obj)[atter]),
		flag = start > target,
		unit = atter==="opacity"?"":"px";

	flag && (speed/=-1);
	(function fn(){
		if(flag?start <= target:start >= target){
			start = target;
			obj.style[atter] = start + unit;
			callback && callback();
		}else{
			start += speed;
			obj.style[atter] = start + unit;
			requestAnimationFrame(fn);
		}
	})();
}

// 样式计算
function getStyle(obj){
	return obj.currentStyle || getComputedStyle(obj);
}